home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d875.lha / Blanker / Source.lha / Source / Blankers / TextD / Text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-24  |  6.5 KB  |  263 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Michael D. Bayne
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include "Text.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = "Workbench";
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *TextWnd = NULL;
  31. struct Gadget         *TextGList = NULL;
  32. struct IntuiMessage    TextMsg;
  33. struct Gadget         *TextGadgets[9];
  34. UWORD                  TextLeft = 0;
  35. UWORD                  TextTop = 12;
  36. UWORD                  TextWidth = 321;
  37. UWORD                  TextHeight = 59;
  38. UBYTE                 *TextWdt = (UBYTE *)"Text Prefs";
  39. struct TextAttr       *Font, Attr;
  40. UWORD                  FontX, FontY;
  41. UWORD                  OffX, OffY;
  42. struct TextFont       *TextFont = NULL;
  43.  
  44. UBYTE *SWITCH0Labels[] = {
  45.     (UBYTE *)"String",
  46.     (UBYTE *)"File",
  47.     NULL };
  48.  
  49. UBYTE *CYCLE0Labels[] = {
  50.     (UBYTE *)"Cycle",
  51.     (UBYTE *)"Random",
  52.     (UBYTE *)"White",
  53.     (UBYTE *)"Copper",
  54.     NULL };
  55.  
  56. UWORD TextGTypes[] = {
  57.     STRING_KIND,
  58.     BUTTON_KIND,
  59.     TEXT_KIND,
  60.     BUTTON_KIND,
  61.     BUTTON_KIND,
  62.     NUMBER_KIND,
  63.     SLIDER_KIND,
  64.     CYCLE_KIND,
  65.     CYCLE_KIND
  66. };
  67.  
  68. struct NewGadget TextNGad[] = {
  69.     81, 2, 236, 14, NULL, NULL, GD_TXT, 0, NULL, (APTR)TXTClicked,
  70.     5, 18, 71, 13, (UBYTE *)"_Font...", NULL, GD_FONT, PLACETEXT_IN, NULL, (APTR)FONTClicked,
  71.     81, 18, 195, 13, NULL, NULL, GD_FTXT, 0, NULL, NULL,
  72.     5, 44, 82, 13, (UBYTE *)"_OK", NULL, GD_OK, PLACETEXT_IN, NULL, (APTR)OKClicked,
  73.     235, 44, 82, 13, (UBYTE *)"_Cancel", NULL, GD_CANCEL, PLACETEXT_IN, NULL, (APTR)CANCELClicked,
  74.     280, 18, 37, 13, NULL, NULL, GD_FSIZE, 0, NULL, NULL,
  75.     81, 33, 195, 9, (UBYTE *)"_Speed", NULL, GD_SPEED, PLACETEXT_LEFT, NULL, (APTR)SPEEDClicked,
  76.     5, 2, 76, 14, NULL, NULL, GD_SWITCH, 0, NULL, (APTR)SWITCHClicked,
  77.     120, 44, 82, 13, NULL, NULL, GD_CYCLE, 0, NULL, (APTR)CYCLEClicked
  78. };
  79.  
  80. ULONG TextGTags[] = {
  81.     (GTST_MaxChars), 128, (TAG_DONE),
  82.     (GT_Underscore), '_', (TAG_DONE),
  83.     (GTTX_Border), TRUE, (TAG_DONE),
  84.     (GT_Underscore), '_', (TAG_DONE),
  85.     (GT_Underscore), '_', (TAG_DONE),
  86.     (GTNM_Border), TRUE, (TAG_DONE),
  87.     (GTSL_Min), 1, (GTSL_Max), 50, (GTSL_Level), 10, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  88.     (GTCY_Labels), (ULONG)&SWITCH0Labels[ 0 ], (TAG_DONE),
  89.     (GTCY_Labels), (ULONG)&CYCLE0Labels[ 0 ], (TAG_DONE)
  90. };
  91.  
  92. static UWORD ComputeX( UWORD value )
  93. {
  94.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  95. }
  96.  
  97. static UWORD ComputeY( UWORD value )
  98. {
  99.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  100. }
  101.  
  102. static void ComputeFont( UWORD width, UWORD height )
  103. {
  104.     Forbid();
  105.     Font = &Attr;
  106.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  107.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  108.     FontX = GfxBase->DefaultFont->tf_XSize;
  109.     Permit();
  110.  
  111.     OffX = Scr->WBorLeft;
  112.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  113.  
  114.     if ( width && height ) {
  115.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  116.             goto UseTopaz;
  117.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  118.             goto UseTopaz;
  119.     }
  120.     return;
  121.  
  122. UseTopaz:
  123.     Font->ta_Name = (STRPTR)"topaz.font";
  124.     FontX = FontY = Font->ta_YSize = 8;
  125. }
  126.  
  127. int SetupScreen( void )
  128. {
  129.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  130.         return( 1L );
  131.  
  132.     ComputeFont( 0, 0 );
  133.  
  134.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  135.         return( 2L );
  136.  
  137.     return( 0L );
  138. }
  139.  
  140. void CloseDownScreen( void )
  141. {
  142.     if ( VisualInfo ) {
  143.         FreeVisualInfo( VisualInfo );
  144.         VisualInfo = NULL;
  145.     }
  146.  
  147.     if ( Scr        ) {
  148.         UnlockPubScreen( NULL, Scr );
  149.         Scr = NULL;
  150.     }
  151. }
  152.  
  153. int HandleTextIDCMP( void )
  154. {
  155.     struct IntuiMessage    *m;
  156.     int            (*func)();
  157.     BOOL            running = TRUE;
  158.  
  159.     while( m = GT_GetIMsg( TextWnd->UserPort )) {
  160.  
  161.         CopyMem(( char * )m, ( char * )&TextMsg, (long)sizeof( struct IntuiMessage ));
  162.  
  163.         GT_ReplyIMsg( m );
  164.  
  165.         switch ( TextMsg.Class ) {
  166.  
  167.             case    IDCMP_REFRESHWINDOW:
  168.                 GT_BeginRefresh( TextWnd );
  169.                 GT_EndRefresh( TextWnd, TRUE );
  170.                 break;
  171.  
  172.             case    IDCMP_VANILLAKEY:
  173.                 running = TextVanillaKey();
  174.                 break;
  175.  
  176.             case    IDCMP_GADGETUP:
  177.             case    IDCMP_GADGETDOWN:
  178.                 func = ( void * )(( struct Gadget * )TextMsg.IAddress )->UserData;
  179.                 running = func();
  180.                 break;
  181.         }
  182.     }
  183.     return( running );
  184. }
  185.  
  186. int OpenTextWindow( void )
  187. {
  188.     struct NewGadget    ng;
  189.     struct Gadget    *g;
  190.     UWORD        lc, tc;
  191.     UWORD        wleft = TextLeft, wtop = TextTop, ww, wh;
  192.  
  193.     ComputeFont( TextWidth, TextHeight );
  194.  
  195.     ww = ComputeX( TextWidth );
  196.     wh = ComputeY( TextHeight );
  197.  
  198.     wleft = ( Scr->Width - ww )/2 - Scr->WBorRight;
  199.     wtop = ( Scr->Height - wh - Font->ta_YSize )/2 - Scr->WBorBottom;
  200.  
  201.     if ( ! ( TextFont = OpenDiskFont( Font )))
  202.         return( 5L );
  203.  
  204.     if ( ! ( g = CreateContext( &TextGList )))
  205.         return( 1L );
  206.  
  207.     for( lc = 0, tc = 0; lc < Text_CNT; lc++ ) {
  208.  
  209.         CopyMem((char * )&TextNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  210.  
  211.         ng.ng_VisualInfo = VisualInfo;
  212.         ng.ng_TextAttr   = Font;
  213.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  214.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  215.         ng.ng_Width      = ComputeX( ng.ng_Width );
  216.         ng.ng_Height     = ComputeY( ng.ng_Height);
  217.  
  218.         TextGadgets[ lc ] = g = CreateGadgetA((ULONG)TextGTypes[ lc ], g, &ng, ( struct TagItem * )&TextGTags[ tc ] );
  219.  
  220.         while( TextGTags[ tc ] ) tc += 2;
  221.         tc++;
  222.  
  223.         if ( NOT g )
  224.             return( 2L );
  225.     }
  226.  
  227.     if ( ! ( TextWnd = OpenWindowTags( NULL,
  228.                 WA_Left,    wleft,
  229.                 WA_Top,        wtop,
  230.                 WA_Width,    ww + OffX + Scr->WBorRight,
  231.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  232.                 WA_IDCMP,    STRINGIDCMP|BUTTONIDCMP|TEXTIDCMP|NUMBERIDCMP|SLIDERIDCMP|CYCLEIDCMP|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  233.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  234.                 WA_Gadgets,    TextGList,
  235.                 WA_Title,    TextWdt,
  236.                 WA_ScreenTitle,    "Text Prefs",
  237.                 TAG_DONE )))
  238.     return( 4L );
  239.  
  240.     GT_RefreshWindow( TextWnd, NULL );
  241.  
  242.     return( 0L );
  243. }
  244.  
  245. void CloseTextWindow( void )
  246. {
  247.     if ( TextWnd        ) {
  248.         CloseWindow( TextWnd );
  249.         TextWnd = NULL;
  250.     }
  251.  
  252.     if ( TextGList      ) {
  253.         FreeGadgets( TextGList );
  254.         TextGList = NULL;
  255.     }
  256.  
  257.     if ( TextFont ) {
  258.         CloseFont( TextFont );
  259.         TextFont = NULL;
  260.     }
  261. }
  262.  
  263.